package org.example.springboot.dao;

import org.apache.ibatis.annotations.*;
import org.example.springboot.model.InBound;
import org.example.springboot.model.Returns;

import java.util.List;

@Mapper
public interface ReturnsMapper {
    @Insert("insert into returns(product_name, model_number, supplier_name,quantity,totalAmount,return_type,in_order_id,out_order_id) values (#{productName},#{modelNumber}, #{supplierName},#{quantity},#{totalAmount},#{returnType},#{inOrderId},#{outOrderId})")
    int insertReturn(@Param("productName") String productName, @Param("modelNumber") String modelNumber, @Param("supplierName") String supplierName, @Param("quantity") String quantity, @Param("totalAmount") String totalAmount, @Param("returnType") String returnType, @Param("inOrderId") String inOrderId, @Param("outOrderId") String outOrderId);

    @Select("select * from returns")
    List<Returns> getAllReturns();

    @Select("select * from returns where id = #{id}")
    Returns getReturnById(@Param("id")int id);

    @Select("select * from returns " + "where product_name like CONCAT('%', #{keyword}, '%') " + "or model_number like CONCAT('%', #{keyword}, '%')"+ "or supplier_name like CONCAT('%', #{keyword}, '%')"+ "or return_time like CONCAT('%', #{keyword}, '%')"+ "or in_order_id like CONCAT('%', #{keyword}, '%')"+ "or return_type like CONCAT('%', #{keyword}, '%')"+ "or out_order_id like CONCAT('%', #{keyword}, '%')")
    List<Returns> findReturnByKeyword(@Param("keyword")String keyword);

    @Delete("delete from returns where id = #{id}")
    void deleteReturnById(@Param("id")int id);

}
